package cn.pa;
public abstract class AbstractBoilWater {
    protected volatile boolean isReadyFlag = false;

    protected void a_addWater() {
        System.out.println("a_addWater ThreadID:"+Thread.currentThread().getId());

        System.out.println("1.加水");
    }

    protected void b_on() {
        System.out.println("b_on ThreadID:"+Thread.currentThread().getId());
        System.out.println("2.打开煤气");
    }

    protected void c_boiling() throws Exception {
        System.out.println("3-1.烧水中.....");
        System.out.println("异步线程执行c_boiling ThreadID:"+Thread.currentThread().getId());

        Thread.sleep(5000); //模拟烧水的过程，比较耗时
        System.out.println("3-2.水开了");
        isReadyFlag = true;
    }

    protected void d_off() {
        System.out.println("d_off ThreadID:"+Thread.currentThread().getId());

        System.out.println("4.关闭煤气");
    }

    //烧水方法
    public abstract void make() throws Exception;

    protected void playGame() throws Exception {
        Thread.sleep(1200);
        if (!isReadyFlag) {
            System.out.println("playGame ThreadID:"+Thread.currentThread().getId());

            System.out.println("水还没烧开,玩一把游戏");
        }
    }

}

